package librarydemo;

/** 书: 完成“核心类设计”要求（图书） */
public class Book {
    private final String id;
    private final String title;
    private final String author;
    private boolean borrowed = false;

    public Book(String id, String title, String author) {
        if (id == null || id.isBlank()) throw new IllegalArgumentException("书号必填");
        if (title == null || title.isBlank()) throw new IllegalArgumentException("书名必填");
        if (author == null || author.isBlank()) throw new IllegalArgumentException("作者必填");
        this.id = id.trim();
        this.title = title.trim();
        this.author = author.trim();
    }

    public String getId() { return id; }
    public String getTitle() { return title; }
    public String getAuthor() { return author; }
    public boolean isBorrowed() { return borrowed; }
    public void setBorrowed(boolean borrowed) { this.borrowed = borrowed; }

    @Override
    public String toString() {
        return String.format("Book{id='%s', title='%s', author='%s', borrowed=%s}",
                id, title, author, borrowed);
    }
}
